package com.ucar.training;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author XiongMM
 * @date 2019/7/26 13:50
 * @description
 */
public class SecondServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
//        out.print("<html><body>您好，恭喜完成第一个servlet!!!<br/>");
//        String value1 = this.getServletConfig().getInitParameter("key1");
//        out.print("<p>key1的值为："+value1+"</p><br/>");
//        String value2 = this.getServletConfig().getInitParameter("key2");
//        out.print("<p>key2的值为："+value2+"</p><br/>");

        String value3 = this.getServletContext().getInitParameter("context-key1");

        out.print("<h3>context-key1的值为："+value3+"</h3><br/>");

        out.print("<h3>context-path的值为："+this.getServletContext().getContextPath()+"</h3><br/>");

        out.print("<h3>context-realpath的值为："+this.getServletContext().getRealPath("/")+"</h3><br/>");

        this.getServletContext().setAttribute("context-key2","context-value2");
        out.print("</body></html>");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
